-
Notifications
You must be signed in to change notification settings - Fork 324
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
full comparison of candidates #3702
Conversation
Codecov Report
@@ Coverage Diff @@
## master #3702 +/- ##
==========================================
- Coverage 74.47% 73.96% -0.51%
==========================================
Files 269 291 +22
Lines 23925 24722 +797
==========================================
+ Hits 17818 18286 +468
- Misses 5174 5502 +328
- Partials 933 934 +1
📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more |
not sure if it's necessary to make this change, should also follow the suggestions in #3700 |
action/protocol/staking/candidate.go
Outdated
@@ -253,7 +253,37 @@ func (l CandidateList) Less(i, j int) bool { | |||
if res := l[i].Votes.Cmp(l[j].Votes); res != 0 { | |||
return res == 1 | |||
} | |||
return strings.Compare(l[i].Owner.String(), l[j].Owner.String()) == 1 | |||
switch strings.Compare(l[i].Owner.String(), l[j].Owner.String()) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
func (l CandidateList) Less(i, j int) bool {
if res := l[i].Votes.Cmp(l[j].Votes); res != 0 {
return res == 1
}
if res := strings.Compare(l[i].Owner.String(), l[j].Owner.String()); res != 0 {
return res == 1
}
if res := strings.Compare(l[i].Operator.String(), l[j].Operator.String()); res != 0 {
return res == 1
}
return strings.Compare(l[i].Name, l[j].Name) == 1
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- @Liuhaai agree comparing these 2 fields should suffice, and I think since we fix this compare func now, we'd better compare all fields to cover all possible corner cases
- prefer to use
if res != 0 {
return res == 1
}
to be consistent, instead of switch case
SonarCloud Quality Gate failed. 0 Bugs No Coverage information |
case -1: | ||
return false | ||
if res := strings.Compare(l[i].Operator.String(), l[j].Operator.String()); res != 0 { | ||
return res == 1 | ||
} | ||
switch { | ||
case l[i].SelfStakeBucketIdx > l[j].SelfStakeBucketIdx: | ||
return true | ||
case l[i].SelfStakeBucketIdx < l[j].SelfStakeBucketIdx: | ||
return false | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if l[i].SelfStakeBucketIdx != l[j].SelfStakeBucketIdx {
return l[i].SelfStakeBucketIdx > l[j].SelfStakeBucketIdx
}
fix #3700
Current implementation only compares votes and owner addresses. This pr adds more comparisons, which includes all fields in candidate.
Fixes #(issue)
Type of change
Please delete options that are not relevant.
How Has This Been Tested?
Please describe the tests that you ran to verify your changes. Provide instructions so we can reproduce. Please also list any relevant details for your test configuration
Test Configuration:
Checklist: